package com.eudon.design_pattern.behavioral.interpreter;

/**
 * @author eudon
 * @description AND表达式，处理"并且"逻辑
 * @date 2025/9/3
 * @email syd19970616@gmail.com
 * @address <a href="https://gitee.com/eudon">Gitee</a>
 */
public class AndExpression implements RuleExpression {
    private RuleExpression leftExpression;
    private RuleExpression rightExpression;

    public AndExpression(RuleExpression leftExpression, RuleExpression rightExpression) {
        this.leftExpression = leftExpression;
        this.rightExpression = rightExpression;
    }

    @Override
    public boolean interpret(Context context) {
        // AND逻辑：两个表达式都为true时才返回true
        return leftExpression.interpret(context) && rightExpression.interpret(context);
    }

    @Override
    public String toString() {
        return "(" + leftExpression.toString() + " 并且 " + rightExpression.toString() + ")";
    }
}